package com.example.first.thread;

import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author LSQ
 * @Description 练习 synchronized 加 runnable
 * @date 2021/11/5 21:43
 * @Version 1.0
 */

public class Worker implements Runnable {

    private int count;
    private int number;
    private CountDownLatch countDownLatch;

    public Worker(int count, int number) {
        this.count = count;
        this.number = number;
    }

    public void doService1() {
        for (int i = 0; i < 100000000; i++) {
            count++;
            number -= 2;
        }
    }

    public void doService2() {
        for (int i = 0; i < 100000000; i++) {
            count--;
            number += 2;
        }
    }

    @Override
    public void run() {

        doService1();
        doService2();

        System.out.println(Thread.currentThread().getName() + " count: " + count);
        System.out.println(Thread.currentThread().getName() + " number: " + number);

        // countDownLatch.countDown();

    }

/*    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            Worker worker = new Worker();
            worker.setCount(0);
            worker.doService1();
            worker.doService2();
            System.out.println(worker.getCount());
        }

    }*/
}
